package com.example.jobback.controller.seeker;

import com.example.jobback.req.seeker.experience.project.ProjectExperienceReq;
import com.example.jobback.req.seeker.experience.work.WorkExperienceReq;
import com.example.jobback.req.seeker.profile.SeekerReq;
import com.example.jobback.resp.seeker.experience.project.ProjectExperienceResp;
import com.example.jobback.resp.seeker.experience.work.WorkExperienceResp;
import com.example.jobback.resp.seeker.profile.SeekerResp;
import com.example.jobback.result.Result;
import com.example.jobback.service.seeker.SeekerProfileService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @ClassName: SeekerProfileController
 * @Description:求职者-个人中心控制器
 * @Author: lhb
 * @Date: 2025/6/21
 */
@RestController
@RequestMapping("/seeker/profile")
@Tag(name = "求职者-个人中心控制器",description = "求职者个人中心服务对应的相关接口")
public class SeekerProfileController {


    private final SeekerProfileService seekerProfileService;

    public SeekerProfileController(SeekerProfileService seekerProfileService) {
        this.seekerProfileService = seekerProfileService;
    }

    @Operation(summary = "获取基本信息",description = "无参数")
    @GetMapping("/getBasicMessage")
    @ApiResponse(description = "返回求职者响应体")
    public Result<SeekerResp> getBasicMessage(){
        return seekerProfileService.getBasicMessage();
    }


    @Operation(summary = "编辑基本信息",description = "前端交接记得json化")
    @ApiResponse(description = "返回token，前端更新token，重新执行getBasicMessage")
    @PostMapping("/editBasicMessage")
    public Result<Object> editBasicMessage(@Validated
                                           @RequestBody
                                           SeekerReq req){
        return seekerProfileService.editBasicMessage(req);
    }


    @Operation(summary = "上传头像",description = "上传头像，这里的file是MultipartFile类")
    @PostMapping("/uploadAvatar")
    @ApiResponse(description = "返回token，前端更新token，重新执行getBasicMessage")
    public Result<Object> uploadAvatar(@RequestBody
                                       @Parameter(description = "头像文件", required = true)
                                       MultipartFile file){
        return seekerProfileService.uploadAvatar(file);
    }


    @Operation(summary = "编辑项目经历",description = "新增项目经历的话，id设置为-1。id设置为-1后端识别为新增（全部的项目经历传输给我）")
    @PostMapping("/editProjectExperience")
    @ApiResponse(description = "返回token，前端更新token,因为编辑的话没有返回id，后端也没返回，建议前端执行一次获取项目经历覆盖数据（或者这个接口直接返回最新的数据）")
    public Result<Object> editProjectExperience(@Validated
                                                @RequestBody
                                                List<ProjectExperienceReq> reqList){
        return seekerProfileService.editProjectExperience(reqList);
    }


    @Operation(summary = "获取项目经历",description = "无参数")
    @GetMapping("/getProjectExperience")
    @ApiResponse(description = "返回项目经历响应体列表")
    public Result<List<ProjectExperienceResp>> getProjectExperience() {
        return seekerProfileService.getProjectExperience();
    }


    @Operation(summary = "编辑工作经历",description = "与编写项目经历类似")
    @PostMapping("/editWorkExperience")
    @ApiResponse(description = "返回token，前端更新token,因为编辑的话没有返回id，后端也没返回，建议前端执行一次获取工作经历覆盖数据（或者这个接口直接返回最新的数据）")
    public Result<Object> editWorkExperience(@Validated
                                             @RequestBody
                                             List<WorkExperienceReq> reqList){
        return seekerProfileService.editWorkExperience(reqList);
    }


    @Operation(summary = "获取工作经历",description = "无参数")
    @GetMapping("/getWorkExperience")
    @ApiResponse(description = "返回工作经历响应体列表")
    public Result<List<WorkExperienceResp>> getWorkExperience() {
        return seekerProfileService.getWorkExperience();
    }
}
